package com.example.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.model.Student;
import com.example.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SSM {

//    例子一：非redis例子
    @Reference(interfaceClass = StudentService.class,version = "1.0.0",check = false)
    private StudentService studentService;

    @RequestMapping("/student/detail/{id}")
    public String seleteStudent(Model model, @PathVariable("id") Integer id){
        Student student = studentService.selectStudentById(id);
        model.addAttribute("student",student);
        return "studentDetail";
    }

    //    例子二 ：Redis验证码例子
    @RequestMapping("/student/post/{id}")
    public String postTestStudent(Model model,@PathVariable("id") Integer id){
        String s = studentService.randomNumb(id);
        model.addAttribute("randonNumb", s);
        return "studentPostNumb";
    }

    @RequestMapping("/student/test/{id}/{numb}")
    public String getTestStudent(Model model,@PathVariable("id") String id,@PathVariable("numb") String numb){
        String s = studentService.getNumb(id);
        if (numb.equals(s)){
            model.addAttribute("sum",studentService.selectStudentById(Integer.valueOf(id)).getName());
//            model.addAttribute("sum", studentService.selectStudentById(i).getName());

          }else {
              model.addAttribute("sum","验证失败");
          }
        return "studentPostNumb";
    }


}
